/*
 * Copyright 2012-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.spring.initializr.generator.spring.code;

import io.spring.initializr.generator.language.CompilationUnit;
import io.spring.initializr.generator.language.SourceCode;
import io.spring.initializr.generator.language.TypeDeclaration;

import org.springframework.core.Ordered;

/**
 * 相对于 ProjectContributor，xxxCustomizer 不是一个统一的接口， 可把他理解为一种感念和与之对应的命名习惯； 每个 Customizer
 * 都有自己明确的名字，同时也对应了明确的触发逻辑和职责边界。
 * <p>
 * 下面列出框架提供的 Customizer 的说明：
 * <p>
 * MainApplicationTypeCustomizer：自定义 MainApplication 类； MainCompilationUnitCustomizer：自定义
 * MainApplication 编译单元； MainSourceCodeCustomizer：自定义 MainApplication 源码；
 * BuildCustomizer：自定义项目构建工具的配置内容； GitIgnoreCustomizer：自定义项目的 .gitignore 文件；
 * HelpDocumentCustomizer：自定义项目的帮助文档； InitializrMetadataCustomizer：自定义项目初始化配置元数据；这个
 * Customizer 比较特殊，框架会在首次加载元数据配置时调用； ProjectDescriptionCustomizer：自定义 ProjectDescription
 * ；即在生成项目文件之前，允许调整项目描述信息； ServletInitializerCustomizer：自定义 web 应用在类上的配置内容；
 * TestApplicationTypeCustomizer：自定义测试 Application 类； TestSourceCodeCustomizer：自定义测试
 * Application 类的源码。
 * <p>
 * 回调，用于定制应用程序的主源代码。 Invoked with an {@link Ordered order} of {@code 0} by default,
 * considering overriding {@link #getOrder()} to customize this behaviour.
 *
 * @param <T> language-specific type declaration
 * @param <C> language-specific compilation unit
 * @param <S> language-specific source code
 * @author Andy Wilkinson
 */
@FunctionalInterface
public interface MainSourceCodeCustomizer<T extends TypeDeclaration, C extends CompilationUnit<T>, S extends SourceCode<T, C>>
		extends Ordered {

	void customize(S sourceCode);

	@Override
	default int getOrder() {
		return 0;
	}

}
